package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.bo.KeywordCreateBo;
import com.cskaoyan.bean.entity.Keyword;
import com.cskaoyan.bean.vo.BasePageData;
import com.cskaoyan.bean.vo.BaseParam;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.KeywordService;
import com.cskaoyan.utils.BaseRespVoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author break_a_leg
 * @description
 * @date 2021年10月19日 15:13
 */
@RestController
@RequestMapping("admin/keyword")
public class KeywordController {

    @Autowired
    KeywordService keywordService;

    @RequestMapping("list")
    public BaseRespVo list(String keyword, String url, BaseParam param) {
        BasePageData data = keywordService.list(keyword,url,param);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody KeywordCreateBo keywordCreateBo) {
        Keyword keyword = keywordService.create(keywordCreateBo);
        return BaseRespVo.ok(keyword);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Keyword keyword) {
        Keyword data = keywordService.update(keyword);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Keyword keyword) {
        int code = keywordService.delete(keyword);
        return BaseRespVoUtil.respByAffectedRow(code);
    }
}
